CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(FoolGo)

SET(CMAKE_CXX_COMPILER c++)

IF(APPLE)
    SET(BASE_FLAGS ${BASE_FLAGS} -stdlib=libc++)
ENDIF()
SET(GTEST_ROOT /usr/share/gtest-1.7.0)

SET(SRC_DIR src)
SET(TEST_DIR test)
SET(BASE_FLAGS "-std=c++0x -Wno-unused-result -iquote ${SRC_DIR}")
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_CXX_FLAGS_DEBUG "${BASE_FLAGS} -O1 -g")  
SET(CMAKE_CXX_FLAGS_RELEASE "${BASE_FLAGS} -O3")
SET(CMAKE_EXE_LINKER_FLAGS["Debug"] "-g")

AUX_SOURCE_DIRECTORY(${SRC_DIR} SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/board SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/piece_structure SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/math SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/game SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/player SRCS)
AUX_SOURCE_DIRECTORY(${SRC_DIR}/util SRCS)
ADD_EXECUTABLE(foolgo ${SRCS})
SET(LOG4CPLUS_LIB /usr/local/Cellar/log4cplus/1.1.2/lib/liblog4cplus.a)
SET(FOOLGO_LIB ${LOG4CPLUS_LIB})
IF (APPLE)
    SET(FOOLGO_LIB ${FOOLGO_LIB} c++)
ENDIF()
TARGET_LINK_LIBRARIES(foolgo ${FOOLGO_LIB})

SET(BOOST_INCLUDE_DIR /usr/local/Cellar/boost/1.56.0/include/)
SET(LOG4CPLUS_INCLUDE_DIR /usr/local/Cellar/log4cplus/1.1.2/include/)
INCLUDE_DIRECTORIES(${GTEST_ROOT} ${GTEST_ROOT}/include ${BOOST_INCLUDE_DIR} ${LOG4CPLUS_INCLUDE_DIR})

# Test configs.
ENABLE_TESTING()

SET(GTEST_MAIN ${GTEST_ROOT}/src/gtest_main.cc)
SET(TESTS ${SRCS} ${GTEST_MAIN})
AUX_SOURCE_DIRECTORY(${TEST_DIR} TESTS)
AUX_SOURCE_DIRECTORY(${TEST_DIR}/board TESTS)
AUX_SOURCE_DIRECTORY(${TEST_DIR}/game TESTS)
LIST(REMOVE_ITEM TESTS ${SRC_DIR}/foolishgo.cc)
ADD_EXECUTABLE(tests ${TESTS})
SET(TEST_LIB ${GTEST_ROOT}/libgtest.a ${GTEST_ROOT}/libgtest_main.a pthread)
IF (APPLE)
    SET(TEST_LIB ${TEST_LIB} c++)
ENDIF()
TARGET_LINK_LIBRARIES(tests ${FOOLGO_LIB} ${TEST_LIB})

ADD_TEST(NAME BoardTest COMMAND tests)
ADD_TEST(NAME BoardInGmTest COMMAND tests)
ADD_TEST(NAME MonteCarloGameTest COMMAND tests)
ADD_TEST(NAME FreshGameTest COMMAND tests)
